#include "monero_api.h"
#include "tools.h"

#include <string>
#include <iostream>
using namespace std;

INITIALIZE_EASYLOGGINGPP

void test()
{
	string language {"English"};


	// get the program command line options, or
	// some default values for quick check
	string mnemonic_str =  "slid otherwise jeers lurk swung tawny zodiac tusks twang cajun swagger peaches tawny";

	cout << "\n"
		 << "Mnemonic seed    : " << mnemonic_str << endl;


	// change the MyMonero 13 word mnemonic seed
	// to its 16 byte hexadecimal version
	xmreg::secret_key16 hexadecimal_seed;

	// use modified words_to_bytes function.
	xmreg::ElectrumWords::words_to_bytes(mnemonic_str, hexadecimal_seed, language);

	// take the 16 byte hexadecimal_seed, and
	// and perform Keccak hash on it. It will
	// produce 32 byte hash.
	crypto::hash hash_of_seed;

	cn_fast_hash(hexadecimal_seed.data, sizeof(hexadecimal_seed.data), hash_of_seed);

	cout << "\n"
		 << "Hash of seed     : " << hash_of_seed<< endl;


	// having the hashed seed, we can proceed
	// with generation of private and public spend keys.
	// the keccak hash of the seed is used as a seed
	// to generate the spend keys.
	crypto::public_key public_spend_key;
	crypto::secret_key private_spend_key;

	crypto::generate_keys(public_spend_key, private_spend_key,
						  xmreg::get_key_from_hash<crypto::secret_key>(hash_of_seed),
						  true);

	cout << "\n"
		 << "Private spend key: " << private_spend_key << "\n"
		 << "Public spend key : " << public_spend_key  << endl;

	// now we get private and public view keys.
	// to do this, we keccak hash the hash_of_seed again
	crypto::hash hash_of_hash;
	cn_fast_hash(hash_of_seed.data, sizeof(hash_of_seed.data), hash_of_hash);
    cout << "\n"
         << "Hash of seed     : " << hash_of_seed<< endl;

	crypto::public_key public_view_key;
	crypto::secret_key private_view_key;


	crypto::generate_keys(public_view_key, private_view_key,
						  xmreg::get_key_from_hash<crypto::secret_key>(hash_of_hash),
						  true);

	cout << "\n"
		 << "Private view key : " << private_view_key << "\n"
		 << "Public view key  : " << public_view_key  << endl;

	// having all keys, we can get the corresponding monero address
	cryptonote::account_public_address address {public_spend_key, public_view_key};
    string strAddr = cryptonote::get_account_address_as_str(false, false, address);
    cout << "\n"
         << "Address : " << strAddr << endl;

	cout << "\nEnd of program." << endl;
}